using UnityEngine;

namespace WolfCarol.AvgToolkit.UI
{
    public class PanelBase : MonoBehaviour
    {
        public GameObject panelRoot;

        public bool isShow { get; private set; }

        protected virtual void OnShow() { }

        protected virtual void OnHide() { }

        private void Awake()
        {
            isShow = panelRoot.activeSelf;
        }

        public void Show()
        {
            if (!isShow)
            {
                isShow = true;
                panelRoot.SetActive(true);
                OnShow();
            }
        }

        public void Hide()
        {
            if (isShow)
            {
                isShow = false;
                panelRoot.SetActive(false);
                OnHide();
            }
        }

        protected T FindControl<T>(string name) where T : Component
        {
            return panelRoot.transform.Find(name).GetComponent<T>();
        }
    }
}
